package com.aiti.lulian.service.impl;




import cn.hutool.core.util.ArrayUtil;
import com.aiti.base.core.base.service.iml.BaseSerivceImpl;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.dto.ShowRecordAuditDto;
import com.aiti.lulian.entity.ShowRecordAudit;
import com.aiti.lulian.feign.CloudShowManagerSubService;
import com.aiti.lulian.mapper.ShowRecordAuditMapper;
import com.aiti.lulian.service.ShowRecordAuditService;
import com.aiti.lulian.vo.ShowRecordAuditExportVo;
import com.aiti.lulian.vo.ShowRecordAuditVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Authorization;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ShowRecordAuditServiceImpl
        extends BaseSerivceImpl<ShowRecordAuditMapper, ShowRecordAudit>
        implements ShowRecordAuditService {

    @Autowired
    private CloudShowManagerSubService cloudShowManagerSubService;

    @Override
    public List<ShowRecordAuditVo> auditPage(Page page, ShowRecordAuditDto dto) {
        Message userRoleMessage = cloudShowManagerSubService.getRoleByUserId(dto.getUserId());
        if (userRoleMessage == null) {
            throw new RuntimeException("获取角色信息失败！");
        }
        String roleIds = (String)userRoleMessage.getObj();
        if(!StringUtils.isEmpty(roleIds)) {
            String[] roleIdArray = roleIds.split(",");
            if (ArrayUtil.containsAny(roleIdArray, "1")) {
                dto.setAdminFlag(true);
            }else{
                dto.setAdminFlag(false);
            }
        }else{
            dto.setAdminFlag(false);
        }
        return this.getBaseMapper().auditPage(page, dto);

    }

    @Override
    public List<ShowRecordAuditExportVo> auditList(ShowRecordAuditDto dto) {
        Message userRoleMessage = cloudShowManagerSubService.getRoleByUserId(dto.getUserId());
        if (userRoleMessage == null) {
            throw new RuntimeException("获取角色信息失败！");
        }
        String roleIds = (String)userRoleMessage.getObj();
        if(!StringUtils.isEmpty(roleIds)) {
            String[] roleIdArray = roleIds.split(",");
            if (ArrayUtil.containsAny(roleIdArray, "1")) {
                dto.setAdminFlag(true);
            }else{
                dto.setAdminFlag(false);
            }
        }else{
            dto.setAdminFlag(false);
        }
        return this.getBaseMapper().auditList(dto);
    }

    @Override
    public List<ShowRecordAuditVo> getRecordAuditInfo(ShowRecordAuditDto dto) {
        return this.getBaseMapper().getRecordAuditInfo(dto);
    }
}
